package com.zx.scp.controller;

import com.zx.map.service.model.PayCmbModel;
import com.zx.map.service.model.PayCmbResponseModel;
import com.zx.map.utils.MyBeanUtils;
import com.zx.scp.service.PayCmbService;
import com.zx.scp.service.model.QueryCmbModel;
import com.zx.scp.service.model.QueryCmbResponseModel;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/payCmb")
public class PayCmbController {

    /**
     * log
     */
    private static Logger log = Logger.getLogger(PayCmbController.class);

    @Autowired
    private PayCmbService payCmbService;

    @RequestMapping("/creditPay")
    @ResponseBody
    public PayCmbResponseModel creditPay(String params, Model model,
                                  HttpServletRequest request) {
        try {
        	log.debug("资金出款请求："+params);
            PayCmbModel payCmbModel = MyBeanUtils.jsonToBean(params, PayCmbModel.class);
            return payCmbService.getPayResponse(payCmbModel);
        } catch (Exception e) {
        	log.info("系统内部异常", e);
        	PayCmbResponseModel payCmbResponseModel = new PayCmbResponseModel();
            payCmbResponseModel.setReturnCode("9999");
            payCmbResponseModel.setErrMsg("");            
            return payCmbResponseModel;
        }
    }
    
    @RequestMapping("/queryPay")
    @ResponseBody
    public QueryCmbResponseModel queryPay(String params, Model model,
                                  HttpServletRequest request) {
        try {
        	log.debug("交易查询请求："+params);
            QueryCmbModel queryCmbModel = MyBeanUtils.jsonToBean(params, QueryCmbModel.class);
            return payCmbService.queryPayInfoResponse(queryCmbModel);
        } catch (Exception e) {
        	log.info("系统内部异常", e);
        	QueryCmbResponseModel queryCmbResponseModel = new QueryCmbResponseModel();
        	queryCmbResponseModel.setReturnCode("9999");
        	queryCmbResponseModel.setErrMsg("");            
            return queryCmbResponseModel;
        }
    }
}
